package com.mc.utils;

import java.lang.reflect.Method;

import org.apache.log4j.Logger;
import org.springframework.ui.ModelMap;

import com.mc.model.Path;

public class PathUtil {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = Logger.getLogger(PathUtil.class);
	
    private static Path path = null;
    private static PathUtil pathUtil = new PathUtil();
    private PathUtil(){}
    public static Path setPathParams(String[] params)
    {
    	path = new Path();
    	for(String param:params)
    	{
    		try {
    			String [] strs = StringUtil.splitAConStr(param);
				Method method= path.getClass().getDeclaredMethod(strs[0],java.lang.String.class);
				//logger.info(method.getName() + "  ");
				method.invoke(path, strs[1]);
			} catch (NoSuchMethodException e) {
				logger.info(e.getMessage());
				e.printStackTrace();
			} catch (Exception e) {
				logger.info(e.getMessage());
				e.printStackTrace();
			}
    		
    	}
    	
    	return path;
    }
    public static String returnStr(Path path,ModelMap modelMap)
    {
    	modelMap.addAttribute("sMenu",path.getSmenu());
    	modelMap.addAttribute("mMenu", path.getMmenu());

    	modelMap.addAttribute("mmMenu", path.getMmmenu());
    	//logger.info(path.getPackageName()+"."+path.getViewName() + "." + path.getViewTitle());
    	return path.getPackageName()+"."+path.getViewName() + "." + path.getViewTitle();
    }
}
